/* Yet Another Experimental Software Renderer
 *
 * Copyright (c) 2010 Pawel "Hery" Dziepak
 */

#include "debug.h"

#ifdef WIN32
#include "windows.h"
#endif

#include <string>
#include <sstream>

namespace yaesr {
	void assert(bool check, const char *expr, long line, const char *file) {
		if (check)
			return;

#ifdef WIN32
		std::stringstream sstr;
		sstr << "Expression:\n\n" << expr << "\n\nfailed on line: " << line << " in file:\n" << file;
		sstr << "\n\nClick Yes to continue, No to run debugger or Cancel to exit.\n";
		int choice = MessageBoxA(NULL, sstr.str().c_str(), "Yaesr - Assertion failed", MB_YESNOCANCEL | MB_ICONERROR);
		if (choice == IDNO)
			Panic();
		else if (choice == IDCANCEL)
			exit(-1);
#endif
	}

	void error(const char *msg, long line, const char *file) {
#ifdef WIN32
		std::stringstream sstr;
		sstr << msg << "\n\non line: " << line << " in file:\n" << file;
		sstr << "\n\nClick OK to run debugger or Cancel to exit.\n";
		int choice = MessageBoxA(NULL, sstr.str().c_str(), "Yaesr - Critical error", MB_OKCANCEL | MB_ICONERROR);
		if (choice == IDOK)
			Panic();
		else
			exit(-1);
#endif
	}


	void warning(const char *msg, long line, const char *file) {
#ifndef NDEBUG
#ifdef WIN32
		std::stringstream sstr;
		sstr << msg << "\n\non line: " << line << " in file:\n" << file;
		sstr << "\n\nClick Yes to continue, No to run debugger or Cancel to exit.\n";
		int choice = MessageBoxA(NULL, sstr.str().c_str(), "Yaesr - Warning", MB_YESNOCANCEL | MB_ICONEXCLAMATION);
		if (choice == IDNO)
			Panic();
		else if (choice == IDCANCEL)
			exit(-1);
#endif
#else
		(msg);
		(line);
		(file);
#endif
	}

}